﻿#region

using System;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Minion.Win.Client.Helper;
using Minion.Win.Client.Models;

#endregion

namespace Minion.Win.Client.Views
{
    public partial class LocationItemDetailView : PhoneApplicationPage
    {
        private Guid _pageId;

        public LocationItemDetailView()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var itemId = NavigationContext.QueryString["id"];
            _pageId = string.IsNullOrEmpty(itemId) ? new Guid() : new Guid(itemId);
            SearchAndSetPageContext();
        }

        private void SearchAndSetPageContext()
        {
            var locationItemDetail = Utilities.FindObject<LocationItemDetail>(App.CurrentLocationDetails, _pageId);
            Dispatcher.BeginInvoke(() => { DataContext = locationItemDetail; });
        }
    }
}